package io.renren.modules.yckj.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.yckj.dao.MachineDao;
import io.renren.modules.yckj.dto.MachineDTO;
import io.renren.modules.yckj.entity.MachineEntity;
import io.renren.modules.yckj.service.MachineService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 机器表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2025-04-16
 */
@Service
public class MachineServiceImpl extends CrudServiceImpl<MachineDao, MachineEntity, MachineDTO> implements MachineService {

    @Override
    public QueryWrapper<MachineEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");
        String name = (String) params.get("name");
        Object status = params.get("status");

        QueryWrapper<MachineEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
        wrapper.eq(ObjectUtil.isAllNotEmpty(status), "status", status);
        wrapper.like(StrUtil.isNotBlank(name), "name",  name  );

        return wrapper;
    }


    @Override
    public List<MachineDTO> getMachineListByProjectId(Map<String, Object> params) {
        List<MachineEntity> entityList = baseDao.getMachineListByProjectId(params);
        return ConvertUtils.sourceToTarget(entityList, MachineDTO.class);
    }
}